<template>
  <div class="wrap">
    <div class="header">
      <div class="left">
        <el-select
          v-model="queryParams.remittanceAccount"
          placeholder="请选择"
          size="small"
          class="header-select mgb10"
          @change="changeOption"
          clearable
        >
          <el-option :label="$t('remittance.Total collection account')" value=""></el-option>
          <el-option
            v-for="item in remittanceAccountList"
            :key="item.id"
            :label="item.select_name"
            :value="item"
          ></el-option>
        </el-select>
      </div>
      <div class="right">
        <div style="display: inline-block; width: 300px;">
          <el-input
            size="small"
            style="width: 200px; margin-right: 10px; margin-bottom: 10px"
            v-model="queryParams.keyword"
            :placeholder="$t('remittance.Search user name')"
            @keyup.enter.native="changeOption(true)"
            clearable @clear="changeOption(false, 'clear')"
          ></el-input>
          <el-button size="small" type="primary" @click="changeOption(true)">{{ $t('common.search') }}</el-button>
        </div>
      </div>
    </div>
    <div class="content">
      <el-table
        v-loading="loading"
        :data="data"
        border
        v-tableHeight="{bottomOffset: 80}"
        height="100px"
        ref="tableData"
      >
        <el-table-column
          prop="createDate"
          :label="$t('remittance.Creation time')"
          align="center"
          min-width="100"
        >
        </el-table-column>
        <el-table-column
          prop="userName"
          :label="$t('remittance.username')"
          align="center"
          min-width="100"
        >
        </el-table-column>
        <el-table-column
          prop="money"
          :label="$t('remittance.Recharge amount')"
          align="center"
          min-width="100"
        >
        </el-table-column>
        <el-table-column
          prop="account"
          :label="$t('remittance.Collection account')"
          align="center"
          min-width="100"
        >
          <template slot-scope="{row}">
            <div
              v-for="(item, index) in row.account"
              :key="index"
            >
              {{item}}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          :label="$t('remittance.operate')"
          align="center"
          min-width="100"
        >
          <template slot-scope="{row}">
            <span style="cursor: pointer;" @click="detail(row)">{{$t('remittance.detail')}}</span>
          </template>
        </el-table-column>
      </el-table>
      <div class="page-wrap">
        <el-pagination
          @current-change="getData"
          :current-page.sync="queryParams.page"
          :page-size="queryParams.pageSize"
          :total="total"
          layout="total, prev, pager, next, jumper"
        >
        </el-pagination>
      </div>
    </div>

    <el-dialog
      width="50%"
      :title="`${$t('remittance.Remittance details')}`"
      :visible.sync="remittanceDialog"
      style="max-height: 800px;overflow-y: auto;"
    >
      <div style="margin-top: -15px; font-weight: 900; font-size: 16px">
        <div style="display: inline-block; width: 80px">
          <span>{{$t('remittance.username')}}：</span>
        </div>
        <div style="display: inline-block">
          <span>{{dataItem.userName}}</span>
        </div>
      </div>
      <div style="margin-top: 15px; font-weight: 900; font-size: 16px">
        <div style="display: inline-block; width: 80px">
          <span>{{$t('remittance.Remittance amount')}}：</span>
        </div>
        <div style="display: inline-block">
          <span style="color: red">{{dataItem.money}}{{$t('common.RMB')}}</span>
        </div>
      </div>
      <div style="margin-top: 20px;">
        <el-row :gutter="24">
          <el-col
            v-for="(item, index) in dataItem.remittance_account_info"
            :key="item.index"
            :span="24"
            style="margin-bottom: 10px"
          >
            <el-card shadow="hover" style="position: relative">
              <el-col :span="16">
                <el-descriptions class="margin-top" :column="1" size="medium" :colon="false">
                  <el-descriptions-item label="">
                    <span class="union-pay-title">{{$t('remittance.Remittance account information')}}{{index + 1}}：</span>
                  </el-descriptions-item>
                  <el-descriptions-item label="">
                    <div style="display: inline-block; width: 270px">
                      <span class="union-pay-title">{{$t('remittance.Account name')}}：</span>
                      <span class="union-pay-title">{{item.account_name}}</span>
                    </div>
                  </el-descriptions-item>
                  <el-descriptions-item label="">
                    <div style="display: inline-block; width: 270px">
                      <span class="union-pay-title">{{$t('remittance.Bank of deposit')}}：</span>
                      <span class="union-pay-title">{{item.bank_of_deposit}}</span>
                    </div>
                  </el-descriptions-item>
                  <el-descriptions-item label="">
                    <div style="display: inline-block; width: 270px">
                      <span class="union-pay-title">{{$t('remittance.Bank account number')}}：</span>
                      <span class="union-pay-title">{{item.bank_account_number}}</span>
                    </div>
                  </el-descriptions-item>
                </el-descriptions>
              </el-col>

              <el-col :span="8">
                <el-descriptions class="margin-top" :column="1" size="medium" :colon="false">
                  <el-descriptions-item label="">
                    <el-image
                      class="zoomable-image"
                      :src="item.imageUrl"
                      :preview-src-list="previewSrcList"
                    ></el-image>
                    <div style="text-align: center;">
                      <span style="color: #AAAAAA;">{{$t('remittance.Click for larger image')}}</span>
                    </div>
                  </el-descriptions-item>
                </el-descriptions>
              </el-col>
            </el-card>
          </el-col>
        </el-row>
        <div style="margin-top: 10px; font-weight: 900; font-size: 16px">
          <span style="font-weight: 900; font-size: 16px; color: red;">{{$t('remittance.Fill in the actual amount received')}}：</span>
          <el-input style="width: 120px; margin-left: 10px; margin-right: 15px" :placeholder="$t('remittance.Please fill in')" v-model.number="remittanceMoney"></el-input>
          <span style="color: red;">{{$t('common.RMB')}}</span>
          <span style="color: #52c41a; margin-left: 30px" v-if="accordText">{{accordText}}</span>
          <span style="color: #f5222d; margin-left: 30px" v-if="inconformityText">{{inconformityText}}</span>
        </div>
        <div style="margin-top: 20px; font-weight: 900; font-size: 16px">
          <span style="font-weight: 900; font-size: 16px;">{{$t('remittance.Note information')}}：</span>
          <el-input
            type="textarea"
            style="margin-top: 20px"
            :autosize="{ minRows: 4, maxRows: 4}"
            :placeholder="$t('remittance.remittance tis')"
            v-model="textarea">
          </el-input>
        </div>

        <div style="display: flex; justify-content: flex-end; margin-top: 30px;">
          <el-button @click="notTis(dataItem.id)" :loading="controlsLoading" style="width: 130px; font-size: 14px; height: 40px" type="info">{{$t('remittance.No prompt')}}</el-button>
          <el-button @click="verify(dataItem.id)" :loading="controlsLoading" style="width: 130px; font-size: 14px; height: 40px" type="danger">{{$t('remittance.Confirm the top-up information')}}</el-button>
        </div>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {
  handleRemittanceRecord,
  getWaitRemittanceRecordList,
} from "@/api/remittance";
import {deepCopy} from "@/utils";
export default {
  name: "collectionAccountManagement",
  computed: {
    accordText() {
      if (this.remittanceMoney !== '' && this.remittanceMoney === this.dataItem.money) {
        return this.$t('remittance.accordText')
      }
      return false
    },
    inconformityText() {
      if (this.remittanceMoney !== '' && this.remittanceMoney !== this.dataItem.money) {
        return this.$t('remittance.inconformityText')
      }
      return false
    },
  },
  data(){
    return {
      queryParams:{
        page: 1,
        pageSize: 20,
        keyword: '',
        remittanceAccount: '',
      },
      data: [],
      remittanceAccountList: [],
      loading: false,
      total: 0,
      remittanceDialog: false,
      dataItem:{},
      previewSrcList: [],
      remittanceMoney: '',
      textarea: '',
      controlsLoading: false,
      is_search: false,
    }
  },
  created() {
    this.getData()
  },
  updated () {
    this.$nextTick(() => {
      this.$refs['tableData'].doLayout();
    })
  },
  methods: {
    getData(){
      this.loading = true
      getWaitRemittanceRecordList(this.queryParams)
        .then(res=>{
          this.loading = false
          this.data = res.data
          this.total = res.info.total
          this.remittanceAccountList = res.info.remittanceAccountList
        })
    },
    //查看详情
    detail(row){
      this.remittanceDialog = true
      this.dataItem = deepCopy(row)
      this.previewSrcList = this.dataItem.remittance_account_info.map(image => image.imageUrl)
      this.remittanceMoney = ''
      this.textarea = ''
    },
    notTis(id){
      let html = this.$t('remittance.notTis')
      this.$confirm(html, this.$t('remittance.notTisTitle'), {
        dangerouslyUseHTMLString: true,
        confirmButtonText: this.$t('remittance.confirm'),
        cancelButtonClass: this.$t('remittance.cancel'),
      })
        .then(res=>{
          this.controlsLoading = true
          let postData = {
            'id': id,
            'type': 2,
            'remark': this.textarea,
          }
          handleRemittanceRecord(postData)
            .then(res=>{
              this.controlsLoading = false
              if(res.error === 0){
                this.remittanceDialog = false
                this.getData()
                this.$successMessage(res.message)
              }else{
                this.$errorMessage(res.message)
              }
            })
        })
        .catch(res=>{

        });
    },
    verify(id){
      let html = this.$t('remittance.verify')
      this.$confirm(html, this.$t('remittance.verifyTitle'), {
        dangerouslyUseHTMLString: true,
        confirmButtonText: this.$t('remittance.confirm'),
        cancelButtonClass: this.$t('remittance.cancel'),
      })
        .then(res=>{
          if (this.remittanceMoney === '' && this.remittanceMoney <= 0) {
            this.$message.error(this.$t('remittance.Please fill in the actual amount received'));
            return false
          }
          this.controlsLoading = true
          let postData = {
            'id': id,
            'type': 1,
            'remark': this.textarea,
            'remittanceMoney': this.remittanceMoney,
          }
          handleRemittanceRecord(postData)
            .then(res=>{
              this.controlsLoading = false
              if(res.error === 0){
                this.remittanceDialog = false
                this.getData()
                this.$successMessage(res.message)
              }else{
                this.$errorMessage(res.message)
              }
            })
        })
        .catch(res=>{

        });
    },
    changeOption(is_search = false, type = ''){
      if (is_search === true) {
        //判断是否使用过搜索按钮
        this.is_search = true
      }
      if (type === 'clear') {
        if (this.is_search ===false) {
          return
        } else {
          this.is_search = false
        }
      }

      this.queryParams.page = 1;
      this.getData()
    },
  },
}
</script>

<style scoped lang="scss">
.wrap {
  padding: 30px 30px;
  .header{
    display: flex;
    justify-content: space-between;
  }
  .content{
    padding: 20px 0 0;
  }

}
.header-select{
  margin-right: 20px;
}
.form-tips{
  font-size: 12px;
}
.union-pay-title {
  font-weight: 900;
  font-size: 14px;
}
.zoomable-image {
  width: 178px;
  height: 138px;
  transition: transform 0.3s; /* 添加过渡效果，使放大效果更平滑 */
}
.zoomable-image:hover {
  transform: scale(1.2); /* 鼠标移入时放大 1.2 倍，可以根据需要调整 */
}
</style>
